const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../services/user.js');
const common = require('../../utils/common.js');

//获取应用实例
const app = getApp()
Page({
  data: {
    h_d_h: 0,//.h_d_h的高度
    choicenessCirclePageNum: 1,// 精选推荐兴趣圈子页数
    isChoicenessCircle: true,// 是否可以请求精选推荐兴趣圈子数据，用于分页
    choicenessCircleList: [],// 精选的兴趣圈子
    collectionCirclePageNum: 1,// 我收藏的兴趣圈子页数
    isCollectionCircle: true,// 是否可以请求我收藏的兴趣圈子数据，用于分页
    interestCollectionList: [],// 我收藏的兴趣圈子
    participateCirclePageNum: 1,// 我参与的兴趣圈子页数
    interestJoinList: [],// 我参与的兴趣圈子
    isParticipateCircle: true,// 是否可以请求我参与的兴趣圈子数据，用于分页
    exitCircleDialogShow: false,// 圈主退出圈子的弹窗
    exitCircleDialogShow2: false,// 用户退出圈子的弹窗
    circleidIsPlacedtopShow: false,// 参与的兴趣圈子底部是否弹出
    interestJoinCircle: {},// 选中的参与的兴趣圈子
    interestJoinCircleIndex: '',// 选中的兴趣圈子下标
    logininfo: {},// 登录信息
    locationDialogShow: false,// 地址信息未授权弹出提示
    nearLatitude: '',// 当前位置的经度
    nearLongitude: '',// 当前位置的纬度
    nearCircleList: [],// 附近的日记信息
    nearProvinceid: '',// 当前的省的信息
    nearCityid: '',// 当前的市的信息
    isCanNearCircle: true,// 是否可以请求附近信息，用于控制下拉获取更多
    nearCirclePageNum: 1,//互动广场的附近信息的页码
    interestingFocusList: [],// 关注信息的用户的信息
    isCanInterestingFocus: true,// 是否可以请求关注信息中的用户，用于控制下拉获取更多
    interestingFocusPageNum: 1,// 互动广场的关注信息中的用户的页码
    isCanFocusCircle: true,// 是否可以请求关注信息，用于控制下拉获取更多
    focusCircleList: [],// 关注信息
    focusCirclePageNum: 1,// 互动广场的关注信息中的日记的页码
    isCanRecommendCircle: true,// 是否可以请求推荐信息，用于控制下拉获取更多
    recommendCircleList: [],// 推荐信息
    recommendCircleOrderby: "",//推荐信息的排序字段
    recommendCirclePageNum: 1,// 互动广场的推荐信息的页码
    interestingPageNum: 1,//参与关注：页码
    interestingList: [],// 参与关注：有趣的人（用于展示）
    basCatalogList: [],//个性标签：list数据（用于展示）
    allBasCatalogList: [],//个性标签：list数据（所有的）
    interestTagCatalogidArray: [],//用户已选择的个性标签
    checkInterestTagIds: [],//用户新增的个性标签
    deleteInterestTagIds: [],//用户删除的个性标签
    interestTagIdsClickIndex: 1,// 当前展示的个性标签页数的下标（用于换一换）
    tabPositionFixed: "", //页面滚动的时候，“参与关注、互动广场、百科周刊”要显示在顶部
    positionFixed: "",//页面滚动到“关注、推荐、附近”的时候，“关注、推荐、附近”要显示在顶部
    gzCenterDisplay: "none",//【关注】内容是否显示
    tjCenterDisplay: "block",//【推荐】内容是否显示
    fjCenterDisplay: "none",//【附近】内容是否显示
    likeCenterDisplay: "none",//【猜你喜欢】内容是否显示
    xzLabelDisplay: "block",//【选择个性标签】是否显示
    labaPng: '01laba.png',//百科周刊的图标
    titleColorClass: "",//头部class
    tsXqText: "",
    tabs0_show: false,
    tabs1_show: true,
    collapseActive_cyhd: ["1", "2", "3", "4", "5", "6"],//控制参与关注展示的标签
    popup_show: false,// 控制底部弹出层
  },
  onShareAppMessage: function () {
    return {
      title: 'xingqubaike',
      desc: '兴趣百科',
      path: '/pages/index/index'
    }
  },
  /**
   * 页面加载事件
   */
  onLoad: function (options) {
    /*var data={};
    util.post(api.fetchToken()).then(function (res) {
      if (res.access_token != '') {
        return Promise.resolve({
          access_token: res.access_token
        });
      }
    }).then(function (res) {
      data.openid = 'oG2O94hYsvdguiR271OoillAPYzk';
      data.access_token = res.access_token;
      util.post('http://192.168.1.106:7979/handshake-provider-xswl-my/api/user/getUserMayknow', data).then(function (res) {
        console.log(res);
      })
    })*/
    //好友助力签到
    /*var date = new Date();
    var time = date.getTime();
    wx.navigateTo({
      url: '../../grade/pages/grade/sign/helpSign/helpSign?openid=oG2O94qnIyvDILqqKVmHzcuV-eZs&helpDate=' + '2019-06-28' + '&helpTime=' + time
    })*/
    //身份认证
    /*wx.navigateTo({
      url: '../../grade/pages/grade/authentication/authentication',
    })*/
    //晋级VIP
    /*wx.navigateTo({
      url: '../../grade/pages/grade/promotedVIP/promotedVIP',
    })*/
    //编辑资料
    /*wx.navigateTo({
      url: '/ucenter/pages/ucenter/personinfo/personinfo',
    })*/
    //图片行程
    /*wx.navigateTo({
      url: '../../interest/pages/interest/journeyImgDetails/journeyImgDetails',
    })*/
    //视频行程
    /*wx.navigateTo({
      url: '../../interest/pages/interest/journeyVideoDetails/journeyVideoDetails',
    })*/
    //契约金
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/createcontract/createcontract?circleid=759',
    })*/
    //地址设置
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personinfo/homesetup/addrsetup/addrsetup',
    })*/
    /*wx.navigateTo({
      url: '../../interest/pages/interest/theme/themeIndex',
    })*/
    //隐私设置
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personinfo/homesetup/yinsi/yinsi',
    })*/
    //主题
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themeIndex?circleid=781',
    })*/
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/makeTheme/makeTheme?o_type=update&themeid=48&circleid=780&type=2',
    })*/
    //主题设置
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/makeTheme/themeSet/themeSet?type=5',
    })*/
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/makeTheme/punchSetting/punchSetting?circleid=777&contentType=2&themeSetting=' + JSON.stringify(data),
    })*/
    //主题详情
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themeDetails/themeDetails?preview=0&themeid=49',
    })*/
    //主题详情
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themeDetails/themeRanking/themeRanking',
    })*/
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themeDetails/themeResult/themeResult?themeid=69&previewType=1',
    })*/
    //付费确认
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themeDetails/purchaseDetails/purchaseDetails',
    })*/
    //订单中心
    /*wx.navigateTo({
      url: '/interest/pages/interest/orderCentre/orderCentre',
    })*/
    //主题管理
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themManage/themManage?circleid=803',
    })*/
    //创建主题组
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themManage/setThemeGroup/setThemeGroup?circleid=777',
    })*/
    //主题组详情
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themManage/groupDetails/groupDetails?circleid=777&groupid=24',
    })*/
    //主题搜索
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themManage/searchTheme/searchTheme?circleid=777',
    })*/
     //主题优惠券
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/themManage/discount/discount',
    })*/
    //宝贝详情
    /*wx.navigateTo({
      url: '/interest/pages/interest/theme/goodsDetails/goodsDetails?themeid=73',
    })*/ 
    /*wx.navigateTo({
      url: '/interest/pages/interest/makeImage/publishJourneyVideo/publishJourneyVideo',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/publish/publish',
    })*/
    //店铺设置
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personinfo/store/store',
    })*/
    //个人主页
    /*wx.navigateTo({

      url: '../../ucenter/pages/ucenter/personhome/personhome',
    })*/
    /*wx.navigateTo({
      url: '../../interest/pages/interest/givingticket/givingticket',
    })*/
    /*wx.navigateTo({
      url: '/pages/home/shareJump/shareJump?id=32&type=5&isCheckLogin=1&circleid=771&shareOpenid=oG2O94qnIyvDILqqKVmHzcuV-eZs',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/circledetails/circledetails?circleid=774&poTopViewIndex=1',
    })*/
    /*wx.navigateTo({
      url: '../../interest/pages/interest/order/order?orderNum=xswl20190717235409836101',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/growingSeeds/growingSeeds?seedid=1&seedname=西瓜',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/circleopt/circleopt?circleid=767',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/editdetails?circleid=803&energyInfoResults=false',
    })*/
    /*wx.navigateTo({
      url: 'shareJump/shareJump?id=39&type=' + util.getShareType("diary") + "&isCheckLogin=1&circleid=33"
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/circleinteraction/diaryDetails/diaryDetails?circleid=33&diaryid=39&diaryIndex=1',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/circleinteraction/circleinteraction?circleid=803',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/registrationfee/details/index?circleid=114',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/registrationfee/registrationfee2?circleid=774',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/editdetails?circleid=762',
    })*/
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/circleinteraction/noThemeClock/noThemeClock?circleid=780&themeid=48',
    })*/
    /*wx.navigateTo({
      url: '../home/weekly/editorAlbumDetails/editorAlbumDetails?albumTitle=123&albumSlogan=456&albumTypeId=1&albumTypeName=3445&type=0',
    })*/
    
    var _this = this;
    // 加载有趣的人
    _this.interesting();
    // 加载互动广场的推荐信息
    _this.recommendCircle();
    // 加载互动广场的关注信息
    _this.focusCircle();
    // 加载【精选的兴趣圈子】数据
    _this.choicenessCircle();
    // 加载【我参与的兴趣圈子】数据
    _this.participateCircle();
    // 加载【我收藏的兴趣圈子】数据
    _this.collectionCircle();
    //  设置标题
    wx.setNavigationBarTitle({
      title: '首页',
    });

    // 获取时间段以及标题颜色
    var periodTime = _this.onThisPeriodTime();
    var tsXqText = periodTime.tsXqText;
    var backgroundColor = periodTime.backgroundColor;
    var titleColorClass = periodTime.titleColorClass;
    // 设置标题字体颜色、背景颜色
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: backgroundColor
    });
    
    _this.setData({
      logininfo: app.globalData.logininfo,
      titleColorClass: titleColorClass,
      tsXqText: tsXqText
    });
    console.log(_this.data.logininfo)
  },

  /**
   * 获取当前时间段
   */
  onThisPeriodTime: function () {
    var hour = new Date().getHours();
    var backgroundColor = "#10284a";//默认颜色为晚上
    var titleColorClass = "evening";
    var tsXqText = "探索兴趣圈子，与你进入梦乡";
    if (hour >= 5 && hour < 10) {
      // 早上
      backgroundColor = "#96ddf9";
      titleColorClass =  "morning";
      tsXqText = "探索兴趣圈子，陪你早起健身";
    } else if (hour >= 10 && hour < 14) {
      // 中午
      backgroundColor = "#91d6ff";
      titleColorClass = "noon";
      tsXqText = "探索兴趣圈子，陪你共进美食";
    } else if (hour >= 14 && hour < 19) {
      // 下午
      backgroundColor = "#cda27c";
      titleColorClass = "afternoon";
      tsXqText = "探索兴趣圈子，陪你共享读书下午茶";
    }
    return { "backgroundColor": backgroundColor, "titleColorClass": titleColorClass, "tsXqText": tsXqText};
  },

  onReady: function () {

  },
  onShow: function (options) {
    // 页面显示
    var _this = this;
    if (app.globalData.logininfo.openid != '' && app.globalData.logininfo.openid != null) {
      _this.setData({
        logininfo: app.globalData.logininfo,
        openid: app.globalData.logininfo.openid
      });
    }
    // 加载27个个性标签
    _this.personalityLabel();
    if (app.switchData ==10){
      _this.changetab1();
      app.switchData = 99999;
    }
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  //跳转到TAB1
  changetab1: function(){
    var _this = this;
    _this.setData({
      titleColorClass: '',
      labaPng: 'laba.png',
      tabs0_show: true,
      tabs1_show: false
    });
    // 设置标题字体颜色、背景颜色
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#fe7f0c'
    });
  },
  /**
   * tabs切换
   */
  tabsChange: function(e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    switch (index) {
      case "0":
        _this.setData({
          titleColorClass: '',
          labaPng: 'laba.png', 
          tabs0_show: true,
          tabs1_show: false
        });
        // 设置标题字体颜色、背景颜色
        wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: '#fe7f0c'
        });
        break;
      case "1":
        // 获取时间段以及标题颜色
        var periodTime = _this.onThisPeriodTime();
        var backgroundColor = periodTime.backgroundColor;
        var titleColorClass = periodTime.titleColorClass;
        // 设置标题字体颜色、背景颜色
        wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: backgroundColor
        });
        _this.setData({
          titleColorClass: titleColorClass,
          labaPng: '01laba.png',
          tabs0_show: false,
          tabs1_show: true
        });
        break;
    }
  },

  // 参与互动的collapse联动
  collapseChange_cyhd(event) {
    this.setData({
      collapseActive_cyhd: event.detail
    });
  },

  // 互动广场的collapse联动
  collapseChange_hdgc(event) {
    this.setData({
      collapseActive_hdgc: event.detail
    });
  },

  // 更多
  gd:function(e){

  },

  // 底部弹出层
  popup_show:function(e) {
    /*var _this = this;
    var popup_show = _this.data.popup_show;
    if (popup_show){
      _this.setData({
        popup_show: false,
      })
    }else{
      _this.setData({
        popup_show: true,
      })
    }*/
  },

  // 跳转到百科周刊页面
  toWeekly:function(e){
    wx.navigateTo({
      url: '../home/weekly/weekly',
    })
  },

  /**
   * 展开或隐藏“选择个性标签”
   */
  xzLabelTap: function(){
    var _this = this;
    var xzLabelDisplay = _this.data.xzLabelDisplay;
    var newXzLabelDisplay = "block";
    if (xzLabelDisplay == "block"){
      newXzLabelDisplay = "none";
    }
    _this.setData({
      xzLabelDisplay: newXzLabelDisplay
    });
  },

  /**
   * 监听屏幕滚动 判断上下滚动
   */
  onPageScroll: function (e) {
    var _this = this;
    var scrollTop = parseInt(e.scrollTop);
    if (scrollTop > 0){
      _this.setData({
        tabPositionFixed: "tabPositionFixed"
      })
    } else {
      _this.setData({
        tabPositionFixed: ""
      })
    }

    var tabs1Show = _this.data.tabs1_show;
    if (tabs1Show){
      var h_d_h = _this.data.h_d_h;
      if (h_d_h == null || h_d_h <= 0) {
        var query = wx.createSelectorQuery();
        query.select('.h_d_h').boundingClientRect(function (rect) {
          _this.setData({
            h_d_h: parseInt(rect.height + 52 - 38)
          })
        }).exec();
      } else {
        var xzLabelDisplay = _this.data.xzLabelDisplay;
        if (xzLabelDisplay == "none"){
          var query = wx.createSelectorQuery();
          query.select('.h_d_h').boundingClientRect(function (rect) {
            var n_height = rect.height;
            if (scrollTop >= n_height) {
              _this.setData({
                positionFixed: "positionFixed"
              })
            } else {
              _this.setData({
                positionFixed: ""
              })
            }
          }).exec();
        }else{
          if (scrollTop >= h_d_h) {
            _this.setData({
              positionFixed: "positionFixed"
            })
          } else {
            _this.setData({
              positionFixed: ""
            })
          }
        }
      }
    }
  },

  /**
   * 关注、推荐、附近切换
   */
  focusAndRecom: function(e){
    var _this = this;
    var type = e.currentTarget.dataset.type;
    switch (type) {
      case "1":
        // 关注
        _this.setData({
          gzCenterDisplay: "block",//【关注】内容是否显示
          tjCenterDisplay: "none",//【推荐】内容是否显示
          fjCenterDisplay: "none",//【附近】内容是否显示
          likeCenterDisplay: "none"//【猜你喜欢】内容是否显示
        });
        break;
      case "2":
        // 推荐
        _this.setData({
          gzCenterDisplay: "none",//【关注】内容是否显示
          tjCenterDisplay: "block",//【推荐】内容是否显示
          fjCenterDisplay: "none",//【附近】内容是否显示
          likeCenterDisplay: "none"//【猜你喜欢】内容是否显示
        });
        break;
      case "3":
        // 附近
        _this.nearCircleStart();
        break;
      case "4":
        // 猜你喜欢
        _this.setData({
          gzCenterDisplay: "none",//【关注】内容是否显示
          tjCenterDisplay: "none",//【推荐】内容是否显示
          fjCenterDisplay: "none",//【附近】内容是否显示
          likeCenterDisplay: "block"//【猜你喜欢】内容是否显示
        });
        break;
    }
  },

  // 跳转到寻宝记
  toTreasureHunt: function (e) {
    wx.navigateTo({
      url: '../home/treasureHunt/treasureHunt'
    })
  },

  // 跳转到早起挑战
  toEarlyChallenge: function (e) {
    wx.navigateTo({
      url: '../home/earlyChallenge/earlyChallenge'
    })
  },

  /**
   * 答题pk
   */
  toAnswerQuestions: function (e) {
    wx.navigateTo({
      url: '../home/answerQuestions/answerQuestions'
    })
  },
  /**
   * 每日签到    
   */
  toSign: function (e) {
    wx.navigateTo({
      url: '../../grade/pages/grade/sign/sign'
    })
  },

  /**
   * 创建词条
   */
  toEntry: function (e) {
    wx.navigateTo({
      url: '../home/entry/entry'
    })
  },

  /**
   * 获取27个个性标签
   */
  personalityLabel: function (){
    var _this = this;
    var data = {};
    data.pageNum = 1;
    data.pageSize = 27;
    //是否登录
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.personalityLabelQuery(api.Home_PersonalityLabelApiUrl, data);
      })
    }else{
      _this.personalityLabelQuery(api.Home_PersonalityLabelUrl, data);
    }
  },
  
  /**
   * 个性标签（请求）
   */
  personalityLabelQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var allBasCatalogList = res.result.personalityLabelList;
        var interestTagCatalogidArray = res.result.interestTagCatalogidArray;
        _this.setData({
          interestTagCatalogidArray: interestTagCatalogidArray,
          allBasCatalogList: allBasCatalogList,
          checkInterestTagIds: [],
          deleteInterestTagIds: []
        });
        _this.jsPersonalityLabelQuery(allBasCatalogList, false);
      }
    });
  },

  /**
   * 换一换
   */
  singAndExchange: function(){
    var _this = this;
    var allBasCatalogList = _this.data.allBasCatalogList;
    _this.jsPersonalityLabelQuery(allBasCatalogList, true);
  },

  /**
   * 计算出需要展示的个性标签
   */
  jsPersonalityLabelQuery: function (allBasCatalogList, isJia = false) {
    var _this = this;
    var allBasCatalogSize = allBasCatalogList.length;
    var page = allBasCatalogSize % 9 == 0 ? (allBasCatalogSize / 9) : ((allBasCatalogSize / 9) +1);
    var interestTagIdsClickIndex = _this.data.interestTagIdsClickIndex;
    if (isJia){
      if (interestTagIdsClickIndex >= parseInt(page)) {
        interestTagIdsClickIndex = 1;
      } else {
        interestTagIdsClickIndex = interestTagIdsClickIndex + 1;
      }
    }
    

    // 计算开始下标
    var startIndex = 9 * (interestTagIdsClickIndex - 1);
    // 计算结束下标
    var endIndex = (9 * interestTagIdsClickIndex > allBasCatalogSize ? allBasCatalogSize : 9 * interestTagIdsClickIndex) - 1;
    var basCatalogList = [];
    for (var i = startIndex; i <= endIndex; i++){
      basCatalogList.push(allBasCatalogList[i]);
    }
    _this.setData({
      interestTagIdsClickIndex: interestTagIdsClickIndex,
      basCatalogList: basCatalogList
    })
  },
  
  /**
   * 选好了
   */
  saveInterestTag: function(){
    var _this = this;
    //是否登录
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      var data = {};
      data.openid = openid;
      data.deleteInterestTagIds = _this.data.deleteInterestTagIds;
      data.checkInterestTagIds = _this.data.checkInterestTagIds;
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.access_token = res.access_token;
        util.post(api.Home_SaveInterestTagApiUrl, data).then(function (res) {
          if (res.code == 200) {
            var intereststr = res.result;
            _this.data.logininfo.homeInfo.intereststr = intereststr;
            wx.setStorage({
              key: 'logininfo',
              data: _this.data.logininfo
            });
            _this.personalityLabel(true);
            util.dialogAlert("操作成功");
          }
        })
        
      })
    }
  },

  /**
   * 个性标签选择
   */
  basCatalogChange(event) {
    let _this = this;
    var detail = event.detail;
    var catalogid = _this.data.basCatalogList[event.detail.name].catalogid;
    var interestTagCatalogidArray = _this.data.interestTagCatalogidArray;
    var deleteInterestTagIds = _this.data.deleteInterestTagIds;
    var checkInterestTagIds = _this.data.checkInterestTagIds;
    // 校验此catalogid是否为用户已选择的个性标签
    var isInterestTagCatalogid = false;
    for (var i = 0; i < interestTagCatalogidArray.length; i++) {
      if (catalogid == interestTagCatalogidArray[i]) {
        isInterestTagCatalogid = true;
      }
    }
    if (detail.checked) {
      // 选中
      if (isInterestTagCatalogid){
        // 需要把此catalogid从deleteInterestTagIds删除
        var deleteInterestTagIdIndex = deleteInterestTagIds.indexOf(catalogid);
        deleteInterestTagIds.splice(deleteInterestTagIdIndex, 1);
      }else{
        // 需要把此catalogid写进checkInterestTagIds里
        checkInterestTagIds.push(catalogid);
      }
    } else {
      // 取消选中
      if (isInterestTagCatalogid) {
        // 需要把此catalogid写进deleteInterestTagIds里
        deleteInterestTagIds.push(catalogid);
      } else {
        // 需要把此catalogid从checkInterestTagIds删除
        var checkInterestTagIdIndex = checkInterestTagIds.indexOf(catalogid);
        checkInterestTagIds.splice(checkInterestTagIdIndex, 1);
      }
    }
    _this.setData({
      ['basCatalogList[' + event.detail.name + '].checked']: detail.checked ? "true" : "false",
      checkInterestTagIds: checkInterestTagIds,
      deleteInterestTagIds: deleteInterestTagIds
    })
  },

  /**
   * 获取【关注有趣的人】
   */
  interesting: function(){
    //是否登录
    var _this = this;
    var data = {};
    data.pageNum = _this.data.interestingPageNum;
    data.pageSize = 3;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.interestingQuery(api.Home_InterestingApiUrl, data);
      })
    } else {
      _this.interestingQuery(api.Home_InterestingUrl, data);
    }
  },

  /**
   * 获取【关注有趣的人】：发送请求
   */
  interestingQuery: function (url, data){
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var pageSize = data.pageSize;
        var interestingPageNum = _this.data.interestingPageNum;
        var page = res.result.page;
        var interestingList = res.result.list;
        if (interestingPageNum >= page){
          interestingPageNum = 1;
        }else{
          interestingPageNum = interestingPageNum +1;
        }
        _this.setData({
          interestingList: interestingList,
          interestingPageNum: interestingPageNum
        });
      }
    });
  },

  /**
   * 【关注有趣的人】关注或取消
   */
  interestinFocus: function (e) {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      var wechatopenid = e.currentTarget.dataset.wechatopenid;
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.wechatopenid = wechatopenid;
        data.openid = openid;
        data.access_token = res.access_token;
        _this.interestinFocusQuery(data);
      })
    }
  },

  /**
   * 全部关注
   */
  allInterestinFocus: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var interestingList = _this.data.interestingList;
        for (var i = 0; i < interestingList.length; i++) {
          var wechatopenid = interestingList[i].oepnid;
          var isFocus = interestingList[i].isFocus;
          if (isFocus != "true") {
            var data = {};
            data.wechatopenid = wechatopenid;
            data.openid = openid;
            data.access_token = res.access_token;
            _this.interestinFocusQuery(data);
          }
        }
      });
    }
  },

  /**
   * 【关注有趣的人】关注或取消：发送请求
   */
  interestinFocusQuery: function (data){
    var _this = this;
    var wechatopenid = data.wechatopenid;
    util.post(api.Home_FocusOrCancelApiUrl, data).then(function (res) {
      if (res.code == 200) {
        var count = res.result.count;
        _this.updateFocusInfo(wechatopenid, count);
      }
    })
  },

  /**
   * 获取【我参与的兴趣圈子】数据
   */
  participateCircle: function(){
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.pageNum = _this.data.participateCirclePageNum;
        data.pageSize = 3;
        util.post(api.Home_ParticipateCircleApiUrl, data).then(function (res2) {
          if(res2.code == 200){
            var list = _this.data.interestJoinList;
            var resultList = res2.result.list;
            for (var i = 0; i < resultList.length; i++) {
              list.push(resultList[i]);
            }
            _this.setData({
              interestJoinList: list,
              isParticipateCircle: resultList.length > 0 ? true : false
            })
          }
        })
      });
    }
  },

  /**
   * 获取【我收藏的兴趣圈子】数据
   */
  collectionCircle: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.pageNum = _this.data.collectionCirclePageNum;
        data.pageSize = 3;
        util.post(api.Home_CollectionCircleApiUrl, data).then(function (res2) {
          if (res2.code == 200) {
            var list = _this.data.interestCollectionList;
            var resultList = res2.result.list;
            for (var i = 0; i < resultList.length; i++) {
              list.push(resultList[i]);
            }
            _this.setData({
              interestCollectionList: list,
              isCollectionCircle: resultList.length > 0 ? true : false
            })
          }
        })
      });
    }
  },

  /**
   * 参与的兴趣圈子点击事件
   */
  interestJoinListChange: function(e){
    var _this = this;
    var id = e.currentTarget.dataset.id;
    _this.setData({

    })
  },

  /**
   * 精选的兴趣圈子
   */
  choicenessCircle: function(){
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    var data = {};
    data.pageNum = _this.data.choicenessCirclePageNum;
    data.pageSize = 5;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.choicenessCircleQuery(api.Home_ChoicenessCircleApiUrl, data);
      });
    } else {
      _this.choicenessCircleQuery(api.Home_ChoicenessCircleUrl, data);
    }
  },

  /**
   * 精选的兴趣圈子：请求动作
   */
  choicenessCircleQuery: function(url, data){
    var _this = this;
    util.post(url, data).then(function (res2) {
      if (res2.code == 200) {
        var list = _this.data.choicenessCircleList;
        var resultList = res2.result.list;
        for (var i = 0; i < resultList.length; i++) {
          list.push(resultList[i]);
        }
        _this.setData({
          choicenessCircleList: list,
          isChoicenessCircle: resultList.length > 0 ? true : false
        })
      }
    })
  },

  /**
   * 精选圈子的收藏、点赞、关注的操作
   */
  choicenessCircleTap: function(e){
    var _this = this;
    var id = e.currentTarget.dataset.id;
    var type = e.currentTarget.dataset.type;
    var index = e.currentTarget.dataset.index;
    var openid = app.globalData.logininfo.openid;
    var operation = e.currentTarget.dataset.operation;
    var allInterestCollectionCount = _this.data.choicenessCircleList[index].allInterestCollectionCount;
    var allInterestGivelikeCount = _this.data.choicenessCircleList[index].allInterestGivelikeCount;
    if (openid != null && openid != "") {
      var data = {};
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {

        var data = {};
        data.id = id;
        data.type = type;
        data.openid = openid;
        data.operation = operation;
        data.access_token = res.access_token;
        util.post(api.Home_ChoicenessCircleTapApiUrl, data).then(function (res2) {
          if (res2.code == 200) {
            switch (type) {
              case "1":
                // 收藏
                if (operation == "0") {
                  // 新增动作
                  allInterestCollectionCount = allInterestCollectionCount + 1;
                  _this.setData({
                    ["choicenessCircleList[" + index + "].interestCollectionCount"]: 1,
                    ["choicenessCircleList[" + index + "].allInterestCollectionCount"]: parseInt(allInterestCollectionCount)
                    
                  })
                } else if (operation == "1") {
                  // 删除动作
                  allInterestCollectionCount = allInterestCollectionCount - 1;
                  _this.setData({
                    ["choicenessCircleList[" + index + "].interestCollectionCount"]: 0,
                    ["choicenessCircleList[" + index + "].allInterestCollectionCount"]: parseInt(allInterestCollectionCount)
                  })
                }
                break;
              case "2":
                // 点赞
                if (operation == "0") {
                  // 新增动作
                  allInterestGivelikeCount = allInterestGivelikeCount + 1;
                  _this.setData({
                    ["choicenessCircleList[" + index + "].interestGivelikeCount"]: 1,
                    ["choicenessCircleList[" + index + "].allInterestGivelikeCount"]: parseInt(allInterestGivelikeCount)
                  })
                } else if (operation == "1") {
                  // 删除动作
                  allInterestGivelikeCount = allInterestGivelikeCount - 1;
                  _this.setData({
                    ["choicenessCircleList[" + index + "].interestGivelikeCount"]: 0,
                    ["choicenessCircleList[" + index + "].allInterestGivelikeCount"]: parseInt(allInterestGivelikeCount)
                  })
                }
                break;
              case "3":
                // 加入圈子：应该是进入圈子详情页面
                
                break;
            }
          }
        })
      });
    }
  },

  /**
   * 进入圈子详情页面
   */
  navigateToCircleInfo: function (e) {
    var _this = this;
    var circleid = e.currentTarget.dataset.circleid;
    var openid = app.globalData.logininfo.openid;
    var data = {};
    data.circleid = circleid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.userIsCircleJoinQuery(api.Home_UserIsCircleJoinApiUrl, data);
      })
    } else {
      _this.userIsCircleJoinQuery(api.Home_UserIsCircleJoinUrl, data);
    }
  },

  /**
   * 校验用户是否为已加入的圈子：请求
   */
  userIsCircleJoinQuery: function(url, data){
    var _this = this;
    util.post(url, data).then(function (res) {
      var userIsCircleJoin = false;
      if (res.code == 200) {
        userIsCircleJoin = res.result.userIsCircleJoin;
      }
      if (userIsCircleJoin) {
        // 已加入
        wx.navigateTo({
          url: '../../../../../ucenter/pages/ucenter/personcenter/editdetails/circleinteraction/circleinteraction?circleid=' + data.circleid,
        })
      } else {
        // 未加入
        wx.navigateTo({
          url: '../../ucenter/pages/ucenter/personcenter/editdetails/circledetails/circledetails?circleid=' + data.circleid,
        })
      }
    });
  },

  /**
   * 获取首页互动广场的推荐信息
   */
  recommendCircle: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    var data = {};
    data.pageNum = _this.data.recommendCirclePageNum;
    data.pageSize = 10;
    data.orderby = _this.data.recommendCircleOrderby;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.recommendCircleQuery(api.Home_RecommendCircleApiUrl, data);
      });
    } else {
      _this.recommendCircleQuery(api.Home_RecommendCircleUrl, data);
    }
  },

  /**
   * 获取首页互动广场的推荐信息：请求动作
   */
  recommendCircleQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res2) {
      if (res2.code == 200) {
        var recommendCircleList = _this.data.recommendCircleList;
        var recommendCircleOrderby = res2.result.str;
        var list = res2.result.list;
        for (var i = 0; i < list.length; i++) {
          recommendCircleList.push(list[i]);
        }
        _this.setData({
          recommendCircleList: recommendCircleList,
          recommendCircleOrderby: recommendCircleOrderby,
          isCanRecommendCircle: list.length > 0 ? true : false
        })
        _this.calculateHeight(1);
      }
    })
  },

  /**
   * 计算高度
   */
  calculateHeight: function (datatype) {
    var _this = this;
    if (datatype == 1) {
        // 推荐
      var recommendCircleList = _this.data.recommendCircleList;
      for (var i = 0; i < recommendCircleList.length; i++) {
        var diaryTextList = recommendCircleList[i].diaryTextList;
        for (var y = 0; y < diaryTextList.length; y++) {
          var id = "#recommendDiaryText_" + i + "_" + y;
          var query = wx.createSelectorQuery();
          query.select(id).boundingClientRect(function (rect) {
            if (rect != null) {
              var id = rect.id;
              var diaryInfoIndex = id.split("_")[1];
              var diaryTextIndex = id.split("_")[2];
              var height = rect.height;
              if (height > 72) {
                _this.setData({
                  ["recommendCircleList[" + diaryInfoIndex + "].diaryTextList[" + diaryTextIndex + "].isOverflow"]: true
                })
              }
            }
          }).exec();
        }
      }
    } else if (datatype == 2){
      // 关注
      var focusCircleList = _this.data.focusCircleList;
      for (var i = 0; i < focusCircleList.length; i++) {
        var diaryTextList = focusCircleList[i].diaryTextList;
        for (var y = 0; y < diaryTextList.length; y++) {
          var id = "#focusDiaryText_" + i + "_" + y;
          var query = wx.createSelectorQuery();
          query.select(id).boundingClientRect(function (rect) {
            if (rect != null) {
              var id = rect.id;
              var diaryInfoIndex = id.split("_")[1];
              var diaryTextIndex = id.split("_")[2];
              var height = rect.height;
              if (height > 72) {
                _this.setData({
                  ["focusCircleList[" + diaryInfoIndex + "].diaryTextList[" + diaryTextIndex + "].isOverflow"]: true
                })
              }
            }
          }).exec();
        }
      }
    } else if (datatype == 3) {
      // 附近
      var nearCircleList = _this.data.nearCircleList;
      for (var i = 0; i < nearCircleList.length; i++) {
        var diaryTextList = nearCircleList[i].diaryTextList;
        for (var y = 0; y < diaryTextList.length; y++) {
          var id = "#nearDiaryText_" + i + "_" + y;
          var query = wx.createSelectorQuery();
          query.select(id).boundingClientRect(function (rect) {
            if (rect != null) {
              var id = rect.id;
              var diaryInfoIndex = id.split("_")[1];
              var diaryTextIndex = id.split("_")[2];
              var height = rect.height;
              if (height > 72) {
                _this.setData({
                  ["nearCircleList[" + diaryInfoIndex + "].diaryTextList[" + diaryTextIndex + "].isOverflow"]: true
                })
              }
            }
          }).exec();
        }
      }
    }
  },

  /**
   * 文字的全文展开
   */
  diaryTextOverflow: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var datatype = e.currentTarget.dataset.datatype;
    if (datatype == 1) {
      // 推荐
      _this.setData({
        ["recommendCircleList[" + index + "].diaryTextList[" + yindex + "].isOverflow"]: false
      })
    } else if (datatype == 2) {
      // 关注
      _this.setData({
        ["focusCircleList[" + index + "].diaryTextList[" + yindex + "].isOverflow"]: false
      })
    } else if (datatype == 3) {
      // 附近 
      _this.setData({
        ["nearCircleList[" + index + "].diaryTextList[" + yindex + "].isOverflow"]: false
      })
    }
  },

  /**
  * 跳转到公众号展示页面：日记
  */
  navigateToWebView: function (e) {
    var ip = e.currentTarget.dataset.ip;
    var text = e.currentTarget.dataset.text;
    var type = e.currentTarget.dataset.type;
    if (type == 1) {
      wx.navigateTo({
        url: '../home/webView/webView?src=' + text,
      })
    } else {
      wx.downloadFile({
        url: ip + text,
        success: function (res) {
          var filePath = res.tempFilePath;
          wx.openDocument({
            filePath: filePath,
            success: function (res) {
            }
          })
        }
      })
    }
  },

  /**
   * 预览图片：日记
   */
  previewImage: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var datatype = e.currentTarget.dataset.datatype;
    var diaryInfo = [];
    if (datatype == 1) {
      // 推荐
      diaryInfo = _this.data.recommendCircleList[index];
    } else if (datatype == 2) {
      // 关注
      diaryInfo = _this.data.focusCircleList[index];
    } else if (datatype == 3) {
      // 附近
      diaryInfo = _this.data.nearCircleList[index];
    }
    var imageList = diaryInfo.imageVideoList;
    var urls = [];
    var current = diaryInfo.imageVideoList[yindex].ip + diaryInfo.imageVideoList[yindex].url;
    for (var i = 0; i < imageList.length; i++) {
      if (imageList[i].imageVideoType == "1") {
        urls.push(imageList[i].ip + imageList[i].url);
      }
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  /**
  * 跳转到视频播放页面：日记
  */
  navigateToVideo: function (e) {
    var _this = this;
    var datatype = e.currentTarget.dataset.datatype;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var diaryInfo = [];
    if (datatype == 1) {
      // 推荐
      diaryInfo = _this.data.recommendCircleList[index];
    } else if (datatype == 2) {
      // 关注
      diaryInfo = _this.data.focusCircleList[index];
    } else if (datatype == 3) {
      // 推荐
      diaryInfo = _this.data.nearCircleList[index];
    }
    var video = diaryInfo.imageVideoList[yindex];
    var diaryid = diaryInfo.ordDiary.id;
    var src = video.ip + video.url;
    wx.navigateTo({
      url: "../home/video/video?state=1&type=2&id=" + diaryid + "&src=" + src
    })
  },

  /**
   * 添加或删除日记能量点赞
   */
  saveOrDeleteOrdDiaryGivelike: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var diaryGivelikeid = e.currentTarget.dataset.givelikeid;
    var datatype = e.currentTarget.dataset.datatype;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        if (datatype == 1) {
          // 推荐
          var data = {};
          data.openid = openid;
          data.access_token = res.access_token;
          data.circleid = _this.data.recommendCircleList[index].ordDiary.circleid;
          data.diaryid = _this.data.recommendCircleList[index].ordDiary.id;
          data.diaryGivelikeid = diaryGivelikeid;
          util.post(api.Home_SaveOrDeleteOrdDiaryGivelikeApiUrl, data).then(function (res) {
            if (res.code == 200) {
              var countDiaryGivelike = _this.data.recommendCircleList[index].countDiaryGivelike;
              if (res.result.obj == null || parseInt(res.result.obj) < 0) {
                _this.setData({
                  ["recommendCircleList[" + index + "].diaryGivelike"]: null,
                  ["recommendCircleList[" + index + "].countDiaryGivelike"]: parseInt(countDiaryGivelike) - 1
                })
              } else {
                _this.setData({
                  ["recommendCircleList[" + index + "].diaryGivelike.id"]: res.result.obj,
                  ["recommendCircleList[" + index + "].countDiaryGivelike"]: parseInt(countDiaryGivelike) + 1
                })
              }
            }
          })
        } else if (datatype == 2) {
          // 关注
          var data = {};
          data.openid = openid;
          data.access_token = res.access_token;
          data.circleid = _this.data.focusCircleList[index].ordDiary.circleid;
          data.diaryid = _this.data.focusCircleList[index].ordDiary.id;
          data.diaryGivelikeid = diaryGivelikeid;
          util.post(api.Home_SaveOrDeleteOrdDiaryGivelikeApiUrl, data).then(function (res) {
            if (res.code == 200) {
              var countDiaryGivelike = _this.data.focusCircleList[index].countDiaryGivelike;
              if (res.result.obj == null || parseInt(res.result.obj) < 0) {
                _this.setData({
                  ["focusCircleList[" + index + "].diaryGivelike"]: null,
                  ["focusCircleList[" + index + "].countDiaryGivelike"]: parseInt(countDiaryGivelike) - 1
                })
              } else {
                _this.setData({
                  ["focusCircleList[" + index + "].diaryGivelike.id"]: res.result.obj,
                  ["focusCircleList[" + index + "].countDiaryGivelike"]: parseInt(countDiaryGivelike) + 1
                })
              }
            }
          })
        } else if (datatype == 3) {
          // 附近
          var data = {};
          data.openid = openid;
          data.access_token = res.access_token;
          data.circleid = _this.data.nearCircleList[index].ordDiary.circleid;
          data.diaryid = _this.data.nearCircleList[index].ordDiary.id;
          data.diaryGivelikeid = diaryGivelikeid;
          util.post(api.Home_SaveOrDeleteOrdDiaryGivelikeApiUrl, data).then(function (res) {
            if (res.code == 200) {
              var countDiaryGivelike = _this.data.nearCircleList[index].countDiaryGivelike;
              if (res.result.obj == null || parseInt(res.result.obj) < 0) {
                _this.setData({
                  ["nearCircleList[" + index + "].diaryGivelike"]: null,
                  ["nearCircleList[" + index + "].countDiaryGivelike"]: parseInt(countDiaryGivelike) - 1
                })
              } else {
                _this.setData({
                  ["nearCircleList[" + index + "].diaryGivelike.id"]: res.result.obj,
                  ["nearCircleList[" + index + "].countDiaryGivelike"]: parseInt(countDiaryGivelike) + 1
                })
              }
            }
          })
        }
      })
    }
  },

  /**
   * 关注或者取消关注
   */
  doUserFocus: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var openid = app.globalData.logininfo.openid;
    var datatype = e.currentTarget.dataset.datatype;
    var focusCircleList = _this.data.focusCircleList;
    var recommendCircleList = _this.data.recommendCircleList;
    var wechatopenid = "";
    if (datatype == 1) {
      // 推荐
      wechatopenid = recommendCircleList[index].ordDiary.openid;
    } else if (datatype == 2) {
      // 关注
      wechatopenid = focusCircleList[index].ordDiary.openid;
    } else if (datatype == 3) {
      // 附近
      wechatopenid = nearCircleList[index].ordDiary.openid;
    }
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.wechatopenid = wechatopenid;
        data.openid = openid;
        data.access_token = res.access_token;
        util.post(api.Home_FocusOrCancelApiUrl, data).then(function (res) {
          if (res.code == 200) {
            var count = res.result.count;
            _this.updateFocusInfo(wechatopenid, count);
          }
        })
      })
    }
  },

  /**
   * 修改关注后的数据
   */
  updateFocusInfo: function (wechatopenid, count) {
    var _this = this;
    var recommendCircleList = _this.data.recommendCircleList;
    for (var i = 0; i < recommendCircleList.length; i++) {
      var o = recommendCircleList[i].ordDiary.openid;
      if (wechatopenid == o) {
        _this.setData({
          ["recommendCircleList[" + i + "].ordDiary.sysUserFocusCount"]: count
        })
      }
    }
    var focusCircleList = _this.data.focusCircleList;
    for (var i = 0; i < focusCircleList.length; i++) {
      var o = focusCircleList[i].ordDiary.openid;
      if (wechatopenid == o) {
        _this.setData({
          ["focusCircleList[" + i + "].ordDiary.sysUserFocusCount"]: count
        })
      }
    }
    var nearCircleList = _this.data.nearCircleList;
    for (var i = 0; i < nearCircleList.length; i++) {
      var o = nearCircleList[i].ordDiary.openid;
      if (wechatopenid == o) {
        _this.setData({
          ["nearCircleList[" + i + "].ordDiary.sysUserFocusCount"]: count
        })
      }
    }
    var interestingList = _this.data.interestingList;
    for (var i = 0; i < interestingList.length; i++) {
      var o = interestingList[i].openid;
      if (wechatopenid == o) {
        _this.setData({
          ["interestingList[" + i + "].isFocus"]: count == 1 ? "true" : "false"
        })
      }
    }
    var interestingFocusList = _this.data.interestingFocusList;
    for (var i = 0; i < interestingFocusList.length; i++) {
      var o = interestingFocusList[i].openid;
      if (wechatopenid == o) {
        _this.setData({
          ["interestingFocusList[" + i + "].isFocus"]: count == 1 ? "true" : "false"
        })
      }
    }
  },

  /**
   * 播放或暂停动作：日记
   */
  voiceBoFang_diary: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var datatype = e.currentTarget.dataset.datatype;
    var diaryAudioList = {};
    if (datatype == 1) {
      // 推荐
      diaryAudioList = _this.data.recommendCircleList[index].diaryAudioList[yindex];
    } else if (datatype == 2) {
      // 关注
      diaryAudioList = _this.data.focusCircleList[index].diaryAudioList[yindex];
    } else if (datatype == 3) {
      // 附近
      diaryAudioList = _this.data.nearCircleList[index].diaryAudioList[yindex];
    }
    var boFangImage = diaryAudioList.boFangImage;
    var ip = diaryAudioList.ip;
    var name = diaryAudioList.name;
    var currentTime = diaryAudioList.currentTime;
    var audiourl = diaryAudioList.url;
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (boFangImage == api.AudioBoFangImage_Name) {
      // 切换至暂停状态
      wx.pauseBackgroundAudio();//暂停播放音乐
      backgroundAudioManager.pause();//暂停播放音乐
      if (datatype == 1) {
        // 推荐
        _this.setData({
          ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
      } else if (datatype == 2) {
        // 关注
        _this.setData({
          ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
      } else if (datatype == 3) {
        // 附近
        _this.setData({
          ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
      }
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio();////暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime;//设置音乐开始时间
      backgroundAudioManager.title = name;
      backgroundAudioManager.src = ip + audiourl;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        if (datatype == 1) {
          // 推荐
          _this.setData({
            ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: "00:00",
            ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: 0,
            ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
          });
        } else if (datatype == 2) {
          // 关注
          _this.setData({
            ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: "00:00",
            ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: 0,
            ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
          });
        } else if (datatype == 3) {
          // 附近
          _this.setData({
            ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: "00:00",
            ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: 0,
            ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
          });
        }
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = parseInt(backgroundAudioManager.currentTime);
        var startDate = util.digitalFormatTime(position);
        if (datatype == 1) {
          // 推荐
          _this.setData({
            ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: backgroundAudioManager.currentTime,
            ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: startDate
          });
        } else if (datatype == 2) {
          // 关注
          _this.setData({
            ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: backgroundAudioManager.currentTime,
            ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: startDate
          });
        } else if (datatype == 3) {
          // 附近
          _this.setData({
            ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: backgroundAudioManager.currentTime,
            ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: startDate
          });
        }
      })
      if (datatype == 1) {
        // 推荐
        _this.setData({
          ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioBoFangImage_Name
        });
      } else if (datatype == 2) {
        // 关注
        _this.setData({
          ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioBoFangImage_Name
        });
      } else if (datatype == 3) {
        // 附近
        _this.setData({
          ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioBoFangImage_Name
        });
      }
    }
  },

  /**
   * 播放音乐（滚动条事件）：日记
   */
  voiceSlider_diary: function (e) {
    var _this = this;
    var position = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var datatype = e.currentTarget.dataset.datatype;
    var diaryAudioList = {};
    if (datatype == 1) {
      // 推荐
      diaryAudioList = _this.data.recommendCircleList[index].diaryAudioList[yindex];
    } else if (datatype == 2) {
      // 关注
      diaryAudioList = _this.data.focusCircleList[index].diaryAudioList[yindex];
    } else if (datatype == 3) {
      // 附近
      diaryAudioList = _this.data.nearCircleList[index].diaryAudioList[yindex];
    }
    var boFangImage = diaryAudioList.boFangImage;
    var startDate = util.digitalFormatTime(position);
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (datatype == 1) {
      // 推荐
      if (boFangImage == api.AudioBoFangImage_Name) {
        //正在播放状态：不知道为什么，录音的在调用backgroundAudioManager.seek(Math.floor(position))方法无效，所以改成一下这种方式
        _this.setData({
          ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: position,
          ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
        _this.voiceBoFang_diary(e);
      } else {
        // 未播放状态
        _this.setData({
          ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: position,
          ["recommendCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: startDate
        });
      }
    } else if (datatype == 2) {
      // 关注
      if (boFangImage == api.AudioBoFangImage_Name) {
        //正在播放状态：不知道为什么，录音的在调用backgroundAudioManager.seek(Math.floor(position))方法无效，所以改成一下这种方式
        _this.setData({
          ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: position,
          ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
        _this.voiceBoFang_diary(e);
      } else {
        // 未播放状态
        _this.setData({
          ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: position,
          ["focusCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: startDate
        });
      }
    } else if (datatype == 3) {
      // 附近
      if (boFangImage == api.AudioBoFangImage_Name) {
        //正在播放状态：不知道为什么，录音的在调用backgroundAudioManager.seek(Math.floor(position))方法无效，所以改成一下这种方式
        _this.setData({
          ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: position,
          ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].boFangImage"]: api.AudioNoBoFangImage_Name
        });
        _this.voiceBoFang_diary(e);
      } else {
        // 未播放状态
        _this.setData({
          ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].currentTime"]: position,
          ["nearCircleList[" + index + "].diaryAudioList[" + yindex + "].startDate"]: startDate
        });
      }
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var _this = this;
    _this.setData({
      interestingPageNum: 1,//参与关注：页码
      interestingList: [],//参与关注：有趣的人（用于展示）
      recommendCircleOrderby: "",//推荐信息的排序字段
      recommendCirclePageNum: 1,// 互动广场的推荐信息的页码
      recommendCircleList: [],// 推荐信息
      focusCirclePageNum: 1,// 互动广场的关注信息的页码
      focusCircleList: [],// 关注信息
      interestingFocusList: [],// 关注信息的用户的信息
      isCanInterestingFocus: true,// 是否可以请求关注信息中的用户，用于控制下拉获取更多
      interestingFocusPageNum: 1,// 互动广场的关注信息中的用户的页码
      isCanFocusCircle: true,// 是否可以请求关注信息，用于控制下拉获取更多
      isCanRecommendCircle: true,// 是否可以请求推荐信息，用于控制下拉获取更多
      choicenessCirclePageNum: 1,// 精选推荐兴趣圈子页数
      isChoicenessCircle: true,// 是否可以请求精选推荐兴趣圈子数据，用于分页
      choicenessCircleList: [],// 精选的兴趣圈子
      collectionCirclePageNum: 1,// 我收藏的兴趣圈子页数
      isCollectionCircle: true,// 是否可以请求我收藏的兴趣圈子数据，用于分页
      interestCollectionList: [],// 我收藏的兴趣圈子
      participateCirclePageNum: 1,// 我参与的兴趣圈子页数
      interestJoinList: [],// 我参与的兴趣圈子
      isParticipateCircle: true,// 是否可以请求我参与的兴趣圈子数据，用于分页
    })
    _this.onLoad();
    _this.onShow();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var _this = this;
    var tabs1_show = _this.data.tabs1_show;
    if (tabs1_show) {
      var gzCenterDisplay = _this.data.gzCenterDisplay;//【关注】内容是否显示
      var tjCenterDisplay = _this.data.tjCenterDisplay;//【推荐】内容是否显示
      var fjCenterDisplay = _this.data.fjCenterDisplay;//【附近】内容是否显示
      var likeCenterDisplay = _this.data.likeCenterDisplay;//【猜你喜欢】内容是否显示
      if (gzCenterDisplay == "block"){
        // 获取更多【关注】信息
        var focusCircleLength = _this.data.focusCircleList.length;
        if (focusCircleLength > 0){
          // 有日记信息，刷新的是关注日记
          var isCanFocusCircle = _this.data.isCanFocusCircle;
          if (isCanFocusCircle) {
            var focusCirclePageNum = _this.data.focusCirclePageNum;
            _this.setData({
              focusCirclePageNum: focusCirclePageNum + 1
            })
            _this.focusCircle();
          }
        }else{
          // 没有日记信息，刷新的是关注里的用户
          var isCanInterestingFocus = _this.data.isCanInterestingFocus;
          if (isCanInterestingFocus) {
            var interestingFocusPageNum = _this.data.interestingFocusPageNum;
            _this.setData({
              interestingFocusPageNum: interestingFocusPageNum + 1
            })
            _this.interestingFocus();
          }
        }
      } else if (tjCenterDisplay == "block") {
        // 获取【推荐】关注信息
        var isCanRecommendCircle = _this.data.isCanRecommendCircle;
        if (isCanRecommendCircle) {
          var recommendCirclePageNum = _this.data.recommendCirclePageNum;
          _this.setData({
            recommendCirclePageNum: recommendCirclePageNum + 1
          })
          _this.recommendCircle();
        }
      } else if (fjCenterDisplay == "block") {
        // 获取更多【附近】信息
        var isCanNearCircle = _this.data.isCanNearCircle;
        var nearCircleList = _this.data.nearCircleList;
        if (isCanNearCircle && nearCircleList.length > 0) {
          var nearCirclePageNum = _this.data.nearCirclePageNum;
          _this.setData({
            nearCirclePageNum: nearCirclePageNum + 1
          })
          _this.nearCircle();
        }
      } else if (likeCenterDisplay == "block") {
        // 获取更多【猜你喜欢】信息

      }
    }
  },

  /**
   * 获取首页互动广场的关注信息
   */
  focusCircle: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var focusCirclePageNum = _this.data.focusCirclePageNum;
        var data = {};
        data.pageSize = 10;
        data.openid = openid;
        data.access_token = res.access_token;
        data.pageNum = focusCirclePageNum;
        util.post(api.Home_FocusCircleApiUrl, data).then(function (res) {
          if (res.code == 200) {
            var focusCircleList = _this.data.focusCircleList;
            var list = res.result.list;
            for (var i = 0; i < list.length; i++) {
              focusCircleList.push(list[i]);
            }
            _this.setData({
              focusCircleList: focusCircleList,
              isCanFocusCircle: list.length > 0 ? true : false
            })
            _this.calculateHeight(2);
            if (focusCircleList.length <= 0){
              // 没有关注的日记信息，去获取人来进行关注
              _this.interestingFocus();
            }
          }
        })
      });
    }else{
      // 获取用户进行关注
      _this.interestingFocus();
    }
  },

  /**
   * 获取用户进行关注
   */
  interestingFocus: function () {
    //是否登录
    var _this = this;
    var data = {};
    data.pageNum = _this.data.interestingFocusPageNum;
    data.pageSize = 10;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.interestingFocusQuery(api.Home_InterestingApiUrl, data);
      })
    } else {
      _this.interestingFocusQuery(api.Home_InterestingUrl, data);
    }
  },

  /**
   * 获取用户进行关注：请求
   */
  interestingFocusQuery: function(url, data){
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var list = res.result.list;
        var interestingFocusList = _this.data.interestingFocusList;
        for (var i = 0; i < list.length; i++) {
          interestingFocusList.push(list[i]);
        }
        _this.setData({
          interestingFocusList: interestingFocusList,
          isCanInterestingFocus: list.length > 0 ? true : false
        });
      }
    });
  },

  /**
   * 【关注获取日记】关注或取消
   */
  interestinDiaryFocus: function (e) {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      var wechatopenid = e.currentTarget.dataset.wechatopenid;
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.wechatopenid = wechatopenid;
        data.openid = openid;
        data.access_token = res.access_token;
        util.post(api.Home_FocusOrCancelApiUrl, data).then(function (res) {
          if (res.code == 200) {
            var count = res.result.count;
            _this.updateFocusInfo(wechatopenid, count);
          }
        })
      })
    }
  },

  /**
   * 创建圈子
   */
  navigateToPublic: function(){
    wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/publish/publish',
    })
  },

  /**
   * 添加更多标签
   */
  navigateToInteresttag: function(){
    wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personinfo/homesetup/interesttag/interesttag',
    })
  },

  /**
   * 获取当前位置信息
   */
  nearCircleStart: function (type) {
    var _this = this;
    var nearCircleList = _this.data.nearCircleList;
    if (nearCircleList.length <= 0){
      var nearProvinceid = _this.data.nearProvinceid;
      var nearCityid = _this.data.nearCityid;
      var nearLatitude = _this.data.nearLatitude;
      var nearLongitude = _this.data.nearLongitude;
      if (nearProvinceid.length <= 0 || nearCityid.length <= 0 || nearLatitude.length <= 0 || nearLongitude.length <= 0) {
        wx.getLocation({
          type: 'wgs84',
          success(res) {
            _this.setData({
              nearLatitude: res.latitude,
              nearLongitude: res.longitude
            });
            _this.nearCircle();
            _this.fjCenterDisplayBlock();
          },
          fail: function () {
            // 拒绝授权
            _this.setData({
              locationDialogShow: true
            })
          }
        })
      } else {
        _this.nearCircle();
        _this.fjCenterDisplayBlock();
      }
    } else{
      _this.fjCenterDisplayBlock();
    }
  },

  /**
   * 切换至推荐
   */
  fjCenterDisplayBlock: function(){
    var _this = this;
    _this.setData({
      gzCenterDisplay: "none",//【关注】内容是否显示
      tjCenterDisplay: "none",//【推荐】内容是否显示
      fjCenterDisplay: "block",//【附近】内容是否显示
      likeCenterDisplay: "none"//【猜你喜欢】内容是否显示
    });
  },

  /**
   * 获取首页的互动广场的附近信息
   */
  nearCircle: function (type) {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    var pageNum = _this.data.nearCirclePageNum;
    var provinceid = _this.data.nearProvinceid;
    var cityid = _this.data.nearCityid;
    var latitude = _this.data.nearLatitude;
    var longitude = _this.data.nearLongitude;
    var data = {};
    data.pageSize = 10;
    data.pageNum = pageNum;
    data.provinceid = provinceid;
    data.cityid = cityid;
    data.latitude = latitude;
    data.longitude = longitude;
    if (openid != null && openid != "") {
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.nearCircleQuery(api.Home_NearCircleApiUrl, data);
      });
    } else {
      _this.nearCircleQuery(api.Home_NearCircleUrl, data);
    }
  },

  /**
   * 获取首页的互动广场的附近信息：请求
   */
  nearCircleQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var nearCircleList = _this.data.nearCircleList;
        var json = res.result.json;
        var list = json.list;
        var provinceid = json.provinceid;
        var cityid = json.cityid;
        for (var i = 0; i < list.length; i++) {
          nearCircleList.push(list[i]);
        }
        _this.setData({
          nearCityid: cityid,
          nearProvinceid: provinceid,
          nearCircleList: nearCircleList,
          isCanNearCircle: list.length > 0 ? true : false
        })
        _this.calculateHeight(3);
      }
    });
  },

  /**
   * 地址信息未授权的弹窗取消动作
   */
  locationDialogClose: function(){
    var _this = this;
    _this.setData({
      locationDialogShow: false
    })
  },

  /**
   * 地址信息未授权的弹窗确认动作
   */
  locationDialogSuccess: function(){
    var _this = this;
    wx.openSetting({
      success: function (data) {
        if (data.authSetting["scope.userLocation"] == true) {
          // 授权成功
          _this.nearCircleStart();
          _this.locationDialogClose();
        } else {
          // 授权失败
          _this.locationDialogClose();
        }
      }
    })
  },

  /**
   * 进入用户主页
   */
  navigateToPersonhome: function (e) {
    var openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: '../../../../../ucenter/pages/ucenter/personhome/personhome?openid=' + openid
    })
  },

  /**
   * 参与的兴趣圈子底部弹出
   */
  circleidIsPlacedtopShow: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      circleidIsPlacedtopShow: true,
      interestJoinCircle: _this.data.interestJoinList[index],
      interestJoinCircleIndex: index
    })
  },

  /**
   * 参与的兴趣圈子底部关闭
   */
  circleidIsPlacedtopClose: function () {
    var _this = this;
    _this.setData({
      circleidIsPlacedtopShow: false,
      interestJoinCircle: {},
      interestJoinCircleIndex: ''
    })
  },

  /**
   * 修改参与的兴趣圈子置顶或者取消置顶
   */
  updateCircleidIsPlacedtop: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var interestJoinCircle = _this.data.interestJoinCircle;
        var interestJoinCircleIndex = _this.data.interestJoinCircleIndex;
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.id = interestJoinCircle.id;
        util.post(api.Home_UpdateCircleidIsPlacedtopApiUrl, data).then(function (res) {
          if (res.code == 200) {
            var circleidIsPlacedtop = res.result.circleidIsPlacedtop;
            _this.setData({
              ["interestJoinList[" + interestJoinCircleIndex + "].circleidIsPlacedtop"]: circleidIsPlacedtop
            })
            util.dialogAlert("操作成功");
            _this.circleidIsPlacedtopClose();
            _this.interestJoinListDesc(interestJoinCircleIndex);
          }
        })
      })
    }
  },

  /**
   * 对我参与的兴趣圈子进行排序
   */
  interestJoinListDesc: function (interestJoinCircleIndex){
    var _this = this;
    var interestJoinList = _this.data.interestJoinList;
    var circleidIsPlacedtop = interestJoinList[interestJoinCircleIndex].circleidIsPlacedtop;
    if (circleidIsPlacedtop == 1){
      // 已置顶
      interestJoinList.splice(0, 0, interestJoinList[interestJoinCircleIndex]);
      interestJoinList.splice(interestJoinCircleIndex + 1, 1);
    }else{
      // 取消置顶
      interestJoinList.splice(interestJoinList.length, 0, interestJoinList[interestJoinCircleIndex]);
      interestJoinList.splice(interestJoinCircleIndex, 1);
    }
    _this.setData({
      interestJoinList: interestJoinList
    })
  },

  /**
   * 退出圈子
   */
  exitCircle: function(){
    var _this = this;
    var interestJoinCircle = _this.data.interestJoinCircle;
    var joinCount = interestJoinCircle.joinCount;
    var identityType = interestJoinCircle.identityType;
    if (identityType == 1 && joinCount > 1){
      // 圈主并且还是有其他成员的
      _this.setData({
        exitCircleDialogShow: true
      })
    }else{
      _this.setData({
        exitCircleDialogShow2: true
      })
    }
    _this.setData({
      circleidIsPlacedtopShow: false
    })
  },

  /**
   * 圈主退出圈子弹窗：取消动作
   */
  exitCircleDialogClose: function () {
    var _this = this;
    _this.setData({
      exitCircleDialogShow: false,
      interestJoinCircle: {},
      interestJoinCircleIndex: ''
    })
  },

  /**
   * 圈主退出圈子弹窗：确认动作
   */
  exitCircleDialogSuccess: function () {
    var _this = this;
    var circleid = _this.data.interestJoinCircle.circleid;
    _this.setData({
      exitCircleDialogShow: false,
      interestJoinCircle: {},
      interestJoinCircleIndex: ''
    })
    /*wx.navigateTo({
      url: '../../ucenter/pages/ucenter/personcenter/editdetails/circleinteraction/group/groupSearch/groupSearch?circleid=' + circleid,
    })*/
  },

  /**
   * 用户退出圈子弹窗：取消动作
   */
  exitCircleDialogClose2: function () {
    var _this = this;
    _this.setData({
      exitCircleDialogShow2: false,
      interestJoinCircle: {},
      interestJoinCircleIndex: ''
    })
  },

  /**
   * 用户退出圈子弹窗：确认动作
   */
  exitCircleDialogSuccess2: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var interestJoinCircle = _this.data.interestJoinCircle;
        var interestJoinCircleIndex = _this.data.interestJoinCircleIndex;
        var interestJoinList = _this.data.interestJoinList;
        var data = {};
        data.openid = openid;
        data.access_token = res.access_token;
        data.id = interestJoinCircle.id;
        util.post(api.Home_ExitCircleApiUrl, data).then(function (res) {
          if (res.code == 200) {
            interestJoinList.splice(interestJoinCircleIndex, 1);
            _this.setData({
              interestJoinList: interestJoinList
            })
            _this.exitCircleDialogClose2();
            util.showToast("退出圈子成功", "success");
          } else {
            util.showToast(res.message, "none");
          }
        })
      })
    }
  },

  /**
   * 我参与的兴趣圈子：查看更多
   */
  participateCircleViewMore: function(){
    var _this = this;
    var isParticipateCircle = _this.data.isParticipateCircle;
    if (isParticipateCircle){
      var participateCirclePageNum = _this.data.participateCirclePageNum;
      _this.setData({
        participateCirclePageNum: participateCirclePageNum + 1
      })
      _this.participateCircle();
    }
  },

  /**
   * 跳转到兴趣圈
   */
  switchTabInterest: function(){
    wx.switchTab({
      url: '../interest/interest'
    })
  },

  /**
   * 我收藏的兴趣圈子：更多收藏
   */
  collectionCircleViewMore: function () {
    var _this = this;
    var isCollectionCircle = _this.data.isCollectionCircle;
    if (isCollectionCircle) {
      var collectionCirclePageNum = _this.data.collectionCirclePageNum;
      _this.setData({
        collectionCirclePageNum: collectionCirclePageNum + 1
      })
      _this.collectionCircle();
    }
  },

  /**
   * 更多精选推荐的兴趣圈子
   */
  choicenessCircleViewMore: function(){
    var _this = this;
    var isChoicenessCircle = _this.data.isChoicenessCircle;
    if (isChoicenessCircle) {
      var choicenessCirclePageNum = _this.data.choicenessCirclePageNum;
      _this.setData({
        choicenessCirclePageNum: choicenessCirclePageNum + 1
      })
      _this.choicenessCircle();
    }
  },
  //跳转登陆
  gotologin: function () {
    wx.navigateTo({
      url: '../ucenter/personcenter/login/login',
    })
  },
})
